import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBGongGongCreateTimeModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuSubPage/YBMiShuTongListDetailSubPage.dart';

import 'YBMiShuProvider/YBShuaXinShengYuChiShuEventBus.dart';

enum YBMiShuListDetailType {
  YBGongGongPage,
  YBYouXuanPage,
}


class YBMiShuListDetailPage extends StatefulWidget {

  final String sysCode;
  final String requestCode;
  final YBMiShuListDetailType detailType;

  const YBMiShuListDetailPage({Key key, this.sysCode, this.requestCode, this.detailType}) : super(key: key);

  @override
  _YBMiShuListDetailPageState createState() => _YBMiShuListDetailPageState(sysCode:sysCode,requestCode: requestCode,detailType: detailType);
}

class _YBMiShuListDetailPageState extends State<YBMiShuListDetailPage> {

  final String sysCode;
  final String requestCode;
  final YBMiShuListDetailType detailType;

  _YBMiShuListDetailPageState({this.sysCode, this.requestCode, this.detailType});

  bool select = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            YBChineseText.workTaiShangJiDetailTitle,
            style: YBTextStyle.TextStyle30313320Medium
          ),
        ),
        body:MultiProvider(
          providers:[
            ChangeNotifierProvider(create: (context)=>YBGongGongYouXuanDetailProvider()..getGongGongYouXuanDataList(sysCode, requestCode)),
            ChangeNotifierProvider(create: (context)=>YBGongGongShengYuNumberProvider()..getGongGongYouXuanDataList(sysCode)),
            ChangeNotifierProvider(create:(context)=>YBGongGongQiangDuoProvider()),
          ],
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Expanded(
                  child:Consumer<YBGongGongYouXuanDetailProvider>(
                      builder: (context,gongGongYouXuanList,child){
                        String createTimeStr = "";
                        if (gongGongYouXuanList.gongGongYouXuanModel.requestAssignRecordList != null) {
                          YBGongGongCreateTimeModel createTimeModel = gongGongYouXuanList.gongGongYouXuanModel.requestAssignRecordList.last;
                          createTimeStr = createTimeModel.createTime;
                        }
                        return CustomScrollView(
                          slivers: <Widget>[
                            SliverToBoxAdapter(
                              child: Container(
                                child: Column(
                                  children: [
                                    Container(
                                      color:YBColor.white,
                                      child: Padding(
                                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                        child: Column(
                                          children: [
                                            Container(
                                              height: YBTextStyle.adapterSize20,
                                            ),
                                            Container(
                                              child: Row(
                                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                crossAxisAlignment: CrossAxisAlignment.center,
                                                children: [
                                                  Container(
                                                    child: Text(
                                                      createTimeStr??"",
                                                      style: YBTextStyle.TextStyle1B1C1F15Medium,
                                                    ),
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      "${gongGongYouXuanList.gongGongYouXuanModel.provinceName}-${gongGongYouXuanList.gongGongYouXuanModel.cityName}"??"",
                                                      style: YBTextStyle.TextStyle6E737A13,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize16,
                                            ),
                                            Container(
                                              child: Row(
                                                children: [
                                                  Container(
                                                    child: Image.asset(YBImageStyle.getImagePath('BLBBusinessOppoManager_phonr')),
                                                  ),
                                                  Container(
                                                    width: 5,
                                                  ),
                                                  Container(
                                                    child: Text(
                                                      gongGongYouXuanList.gongGongYouXuanModel.linkPhone??'',
                                                      style: YBTextStyle.TextStyle6E737A13,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize16,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    Container(
                                      height: 8,
                                    ),
                                    Container(
                                      color: YBColor.white,
                                      child: Padding(
                                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          crossAxisAlignment: CrossAxisAlignment.stretch,
                                          children: [
                                            Container(
                                              child: Text(
                                                YBChineseText.workTaiXuQiuNeiRongTitle,
                                                style: YBTextStyle.TextStyle1B1C1F15Medium,
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize15,
                                            ),
                                            Container(
                                              child: Text(
                                                gongGongYouXuanList.gongGongYouXuanModel.requestServiceDesc??"",
                                                style: YBTextStyle.TextStyle6E737A13,
                                              ),
                                            ),
                                            Container(
                                              height: YBTextStyle.adapterSize15,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    Container(
                                      height: YBTextStyle.adapterSize8,
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            SliverToBoxAdapter(
                              child: Container(
                                color:YBColor.white,
                                child: Padding(
                                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize15),
                                  child: Text(
                                    YBChineseText.workTaiMishuDetailliuzhuanJiluTitle,
                                    style: YBTextStyle.TextStyle1B1C1F15Medium,
                                  ),
                                ),
                              ),
                            ),
                            SliverList(
                              delegate:SliverChildBuilderDelegate((_,int index){
                                YBGongGongCreateTimeModel createTimeModel = gongGongYouXuanList.gongGongYouXuanModel.requestAssignRecordList[index];
                                return YBMiShuTongListDetailSubPage(numberStr: (index + 1).toString(),timeStr: createTimeModel.createTime,);
                              },
                                  childCount: gongGongYouXuanList.gongGongYouXuanModel.requestAssignRecordList.length
                              ),
                            ),
                          ],
                        );
                      }
                  )
              ),
              Container(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        child: InkWell(
                          child: select ==false?Image.asset(YBImageStyle.getImagePath("login_default")):Image.asset(YBImageStyle.getImagePath("login_selected")),
                          onTap: () async {
                             setState(() {
                               select = !select;
                             });
                          },
                        ),
                      ),
                      Container(
                        width: 5,
                      ),
                      Container(
                        child: RichText(
                          text:TextSpan(
                            style: YBTextStyle.homeSmallSubText,
                            children:<InlineSpan>[
                              TextSpan(
                                text: YBChineseText.woYiYueDuBingTongYiTitle,
                                style: YBTextStyle.logincolor383A3D13Light,
                              ),
                              TextSpan(
                                  text: YBChineseText.workTaiShangJiKuManangerTitle,
                                  style: YBTextStyle.login2D69E013light,
                                  recognizer: TapGestureRecognizer()..onTap = () {
                                    if (sysCode.contains('xg_newyijiwang')) {
                                      YBApplication.router.navigateTo(context,
                                          "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaYiJiPage");
                                    }else if (sysCode.contains("xg_jinrilvsi")){
                                      YBApplication.router.navigateTo(context,
                                          "/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuShangjikuListDetailPage/workTaiMiShuShangJiManangerIdeaLvSiPage");
                                    }
                                  }
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                height: YBTextStyle.adapterSize6,
              ),
              Container(
                height: YBTextStyle.adapterSize26,
                color: YBColor.common2D69E0,
                alignment: Alignment.centerLeft,
                child:Consumer<YBGongGongShengYuNumberProvider>(
                    builder: (context,dataList,child){
                      shuaXinShengYuchiShuEventBus.on<YBShuaXinShengYuChiShuEventBus>().listen((event) {
                        dataList.getGongGongYouXuanDataList(sysCode);
                      });
                      return Padding(
                        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                        child:  Text(
                          "${YBChineseText.workTaiTodayShengYuShangJiKuTitle}${dataList.todayShengYuNumberStr}次",
                          style: YBTextStyle.TextStyleA9AEB813,
                        ),
                      );
                    }
                ),
              ),
              Container(
                height: YBTextStyle.adapterSize15,
              ),
              Container(
                height: YBTextStyle.adapterSize44,
                child:Consumer<YBGongGongQiangDuoProvider>(builder:(context,qiangduoInfo,child){

                  return  Padding(
                    padding: EdgeInsets.only(left:YBTextStyle.adapterSize20,right:YBTextStyle.adapterSize20),
                    child: MaterialButton(
                        shape: RoundedRectangleBorder(
                          side: BorderSide.none,
                          borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                        ),
                        color: YBColor.commonThemeColor,
                        child: Text(YBChineseText.workTaiHuoQuShangJiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                        onPressed:(){

                          if (select == false){
                             EasyLoading.showInfo(YBChineseText.qingTongYiXieYiTitle);
                             return;
                          }
                          qiangduoInfo.getGongGongYouXuanDataList(sysCode, requestCode);
                        }),
                  );
                }),
              ),
              Container(
                height: YBTextStyle.adapterSize15,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

